package cn.px.sa.admin.module.xjgl.ginspectionabnormal.service;

import cn.px.sa.admin.module.xjgl.ginspectionabnormal.dao.GInspectionAbnormalDao;
import cn.px.sa.admin.module.xjgl.ginspectionabnormal.domain.entity.GInspectionAbnormalEntity;
import cn.px.sa.admin.module.xjgl.ginspectionabnormal.domain.form.GInspectionAbnormalAddForm;
import cn.px.sa.admin.module.xjgl.ginspectionabnormal.domain.form.GInspectionAbnormalQueryForm;
import cn.px.sa.admin.module.xjgl.ginspectionabnormal.domain.form.GInspectionAbnormalUpdateForm;
import cn.px.sa.admin.module.xjgl.ginspectionabnormal.domain.vo.GInspectionAbnormalVO;
import cn.px.sa.base.common.util.SmartBeanUtil;
import cn.px.sa.base.common.util.SmartPageUtil;
import cn.px.sa.base.common.domain.ResponseDTO;
import cn.px.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 巡检异常处理表 Service
 *
 * @author 品讯科技
 * @date 2024-08
 * @Copyright 1
 */

@Service
public class GInspectionAbnormalService {

    @Resource
    private GInspectionAbnormalDao gInspectionAbnormalDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<GInspectionAbnormalVO> queryPage(GInspectionAbnormalQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<GInspectionAbnormalVO> list = gInspectionAbnormalDao.queryPage(page, queryForm);
        PageResult<GInspectionAbnormalVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(GInspectionAbnormalAddForm addForm) {
        GInspectionAbnormalEntity gInspectionAbnormalEntity = SmartBeanUtil.copy(addForm, GInspectionAbnormalEntity.class);

        gInspectionAbnormalEntity.setAssignedTime(LocalDateTime.now());

        gInspectionAbnormalDao.insert(gInspectionAbnormalEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(GInspectionAbnormalUpdateForm updateForm) {
        GInspectionAbnormalEntity gInspectionAbnormalEntity = SmartBeanUtil.copy(updateForm, GInspectionAbnormalEntity.class);
        gInspectionAbnormalDao.updateById(gInspectionAbnormalEntity);
        return ResponseDTO.ok();
    }

}
